package com.service;


import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;

import java.io.IOException;

/**
 * @author wangzhilong
 * @date 2020/4/15
 */
public class AfterMain {

    public static void main(String[] args) {
        try {
            //43846 是jvm 进程ID，这里指的是RunningApp启动后的PID
            final VirtualMachine vm = VirtualMachine.attach("43846");
            //加载代理程序
            vm.loadAgent("/Users/wangdigua/IdeaProjects/spring-boot-samples/java-agent/target/java-agent-1.0.jar");
        } catch (AttachNotSupportedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (AgentLoadException e) {
            e.printStackTrace();
        } catch (AgentInitializationException e) {
            e.printStackTrace();
        }

    }
}
